
/**
 * This controller is invoqued when a new user is connected in the application.
 * @author eKameleon
 */
if ( ewhiteboard.controller.application.ConnectApplication == undefined ) 
{

	/**
	 * Creates a new ConnectApplication instance. 
	 */
	ewhiteboard.controller.application.ConnectApplication = function () 
	{
		//		
	}
	
	/**
	 * @extends andromeda.controller.AbstractController
	 */
	proto = ewhiteboard.controller.application.ConnectApplication.extend( andromeda.controller.AbstractController ) ;

	/**
	 * Handles the event.
	 */
	proto.handleEvent = function ( e /*ApplicationEvent*/ ) 
	{
		
		var type /*String*/ = e.getType() ;
		var client /*Client*/ = e.client ;
		var context /*Array*/ = e.getContext() ; // arguments envoyés via la NetConnection
		
		var name /*String*/  = context[0] ;
		
		LOGGER.debug( this + " handleEvent : " + name ) ;
		
		if ( name == null || ! name instanceof String )
		{
			asgard.APPLICATION.rejectConnection( client , "Connection is rejected, the user id of the client not must be 'null' or 'undefined' and must be a String value." ) ;
		}
		else
		{
			
			var users /*MapModel*/ = andromeda.model.ModelCollector.get( MODEL_LIST.USER_MODEL ) ;
			
			if ( users.containsByProperty( "name", name ) )
			{
				asgard.APPLICATION.rejectConnection( client , "Connection is rejected, the user " + name + " exist in the model of all clients of this application." ) ;
			}
			else
			{
				
				var user /*UserVO*/ = new ewhiteboard.vo.UserVO( name , client ) ;
				
				try
				{
					users.addVO( user ) ;
					asgard.APPLICATION.acceptConnection( client ) ;
				}
				catch( e /*Error*/ )
				{
					asgard.APPLICATION.rejectConnection( client , "Connection is rejected, the user " + name + " can't be insert in the user model : " + e.toString()  ) ;
				}
				
			}
		}
		
	}
	
	delete proto ;
	
}